package solutions.leetcode.normal;

import solutions.lib.BaseSolution;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/repeated-dna-sequences/">187. 重复的DNA序列</a>
 */
public class Solution187 extends BaseSolution {

    public List<String> findRepeatedDnaSequences(String s) {
        Set<String> set = new HashSet<>();
        Set<String> rst = new HashSet<>();
        for (int i = 0, size = s.length(); i <= size - 10; i++) {
            String t = s.substring(i, i + 10);
            if (set.contains(t)) {
                rst.add(t);
            } else {
                set.add(t);
            }
        }

        return new LinkedList<>(rst);
    }

    public static void main(String[] args) {
        Solution187 solution = new Solution187();
        printVals(solution.findRepeatedDnaSequences("AAAAAAAAAAA"));
    }
}